//
//  MovieTwoViewController.m
//  豆瓣HW
//
//  Created by dllo on 15/11/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MovieTwoViewController.h"
#import "MovieTwoView.h"
#import "Movie.h"
#import "DetailMovieViewController.h"

@interface MovieTwoViewController ()

@property (nonatomic, retain) UIScrollView *scrollV;

@end

@implementation MovieTwoViewController

- (void)dealloc
{
    [_array release];
    [_scrollV release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationController.navigationBar.translucent = NO;
    
    self.navigationItem.title = @"电影";
    
    UIImage *rightImage = [UIImage imageNamed:@"btn_nav_list@2x.png"];
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:rightImage style:UIBarButtonItemStylePlain target:self action:@selector(barAction:)];
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:self.view.frame];
    self.scrollV.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 3);
    [self.view addSubview:self.scrollV];
    [_scrollV release];
    
    for (NSInteger i = 0; i < 9; i++) {
        
        for (NSInteger j = 0; j < 3; j++) {
//            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake((110 + 15) * j, (180 + 50) * i, 110, 150)];
//            imageV.backgroundColor = [UIColor blackColor];
//            [self.view addSubview:imageV];
//            [imageV release];
            MovieTwoView *movieTV = [[MovieTwoView alloc] initWithFrame:CGRectMake((110 + 15) * j + 8, (180 + 5) * i + 10, 110, 180)];
            movieTV.label.text = [[self.array objectAtIndex:j * 3 + i] title];
            movieTV.imageV.image = [[self.array objectAtIndex:j * 3 + i] image];
            movieTV.tag = 10000 + j * 3 + i;
            
            UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
            [movieTV addGestureRecognizer:tapGR];
            [tapGR release];
            
            [self.scrollV addSubview:movieTV];
            [movieTV release];
            
        }
    }
    
  
}

- (void)tapAction:(UITapGestureRecognizer *)sender
{
    
    DetailMovieViewController *detailMovieVC = [[DetailMovieViewController alloc] init];
   
    detailMovieVC.mov = [self.array objectAtIndex:sender.self.view.tag - 10000];
    [self.navigationController pushViewController:detailMovieVC animated:YES];
    [detailMovieVC release];

    
    
}

- (void)barAction:(UIBarButtonItem *)sender
{

    [self.navigationController popViewControllerAnimated:YES];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
